home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / zoom.pro < prev   
Text File  |  1997-07-08  |  5KB  |  170 lines

  1. ; $Id: zoom.pro,v 1.8 1997/01/15 03:11:50 ali Exp $
  2.  
  3. pro zoom,xsize=xs, ysize=ys, fact = fact, interp = interp, continuous = cont, $
  4.         keep=keep, zoom_window=zoom_win, new_window=new_win
  5. ;+
  6. ; NAME:    
  7. ;    ZOOM
  8. ;
  9. ; PURPOSE:
  10. ;    Display part of an image (or graphics) from the current window
  11. ;    enlarged in another window.
  12. ;
  13. ;    The cursor is used to mark the center of the zoom.
  14. ;
  15. ; CATEGORY:
  16. ;    Image display.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    ZOOM [, FACT = Fact, /INTERP, XSIZE = Xs, YSIZE = Ys, /CONTINUOUS, $
  20. ;        /KEEP, ZOOM_WINDOW=Zoom_Win, /NEW_WINDOW ]
  21. ;
  22. ; INPUTS:
  23. ;    All input parameters are passed as keywords.
  24. ;
  25. ; KEYWORDS:
  26. ;    FACT:    Zoom factor.  This parameter must be an integer.  The default
  27. ;        zoom factor is 4.
  28. ;
  29. ;    INTERP:    Set this keyword to use bilinear interpolation, otherwise 
  30. ;        pixel replication is used.
  31. ;
  32. ;    XSIZE:    The X size of the zoom window.  The default is 512.
  33. ;
  34. ;    YSIZE:    The Y size of the zoom window.  The default is 512.
  35. ;
  36. ;   CONTINUOUS:    Set this keyword to make the zoom window track the mouse
  37. ;        without requiring the user to press the left mouse button.
  38. ;        This feature only works well on fast computers.
  39. ;
  40. ;         KEEP: Keep the zoom window after exiting the procedure.
  41. ;
  42. ;  ZOOM_WINDOW:    When used with KEEP, returns the index of the zoom window.
  43. ;        Otherwise, if KEEP is not set, then -1 is returned.
  44. ;
  45. ;   NEW_WINDOW:    Normally, if ZOOM is called with /KEEP and then called again,
  46. ;        it will use the same window to display the zoomed image.
  47. ;        Calling ZOOM with /NEW_WINDOW forces it to create a new window
  48. ;        for this purpose.
  49. ;
  50. ; OUTPUTS:
  51. ;    No explicit outputs.   A new window is created if necessary. It
  52. ;    is destroyed upon exit if KEEP is not specified.
  53. ;
  54. ; COMMON BLOCKS:
  55. ;    None.
  56. ;
  57. ; SIDE EFFECTS:
  58. ;    A window is created/destroyed.
  59. ;
  60. ;    When ZOOM is reusing a zoom window from a previous call to ZOOM,/KEEP,
  61. ;    then the XSIZE and YSIZE parameters are reset to the actual size of the
  62. ;    window.
  63. ;
  64. ; RESTRICTIONS:
  65. ;    ZOOM only works with color systems.
  66. ;
  67. ; PROCEDURE:
  68. ;    Straightforward.
  69. ; MODIFICATION HISTORY:
  70. ;    ?
  71. ;       William Thompson, March 1992, added common block ZOOM_WINDOW
  72. ;        and KEEP keyword.
  73. ;    William Thompson, 20 May 1993, added ZOOM_WINDOW and NEW_WINDOW
  74. ;        keywords.
  75. ;
  76. ;-
  77. on_error,2              ;Return to caller if an error occurs
  78. common zoom_window, zoom_w
  79. ;
  80. if n_elements(xs) le 0 then xs = 512
  81. if n_elements(ys) le 0 then ys = 512
  82. if n_elements(fact) le 0 then fact=4
  83. if keyword_set(cont) then waitflg = 2 else waitflg = 3
  84. ifact = fact
  85. old_w = !d.window
  86. if keyword_set(new_win) then zoom_w = -1    ;Don't use old window (if any)
  87. if n_elements(zoom_w) eq 0 then zoom_w = -1        ;No zoom window yet
  88. ;
  89. ;  If an old window is to be used, then make sure it still exists.  (Added by
  90. ;  William Thompson, 20 May 1993.)
  91. ;
  92. if zoom_w ge 0 then begin
  93.     device, window_state=win_state
  94.     if not win_state[zoom_w] then zoom_w = -1
  95. endif
  96. ;
  97. ;  Make sure the parameters xs and ys agree with the size of the window, in
  98. ;  case a window is being reused from a previous call to ZOOM,/KEEP.  (Added by
  99. ;  William Thompson, 20 May 1993.)
  100. ;
  101. IF ZOOM_W GE 0 THEN BEGIN
  102.     OLD_WINDOW = !D.WINDOW
  103.     WSET, ZOOM_W
  104.     XS = !D.X_SIZE
  105.     YS = !D.Y_SIZE
  106.     WSET, OLD_WINDOW
  107. ENDIF
  108. tvcrs,1            ;enable cursor
  109. ierase = 0        ;erase zoom window flag
  110. IF KEYWORD_SET(cont) THEN BEGIN
  111.     PRINT,'Cursor position is zoom center, '+$
  112.           'Middle button for new zoom factor, Right button to quit'
  113. ENDIF ELSE BEGIN
  114.     PRINT,'Left for zoom center, Middle for new zoom factor, Right to quit'
  115. ENDELSE
  116. again:
  117.     cursor,x,y,waitflg,/dev    ;Wait for change
  118.     case !err of
  119. 4:    goto, done
  120. 2:    if !d.name eq 'SUN' or !d.name eq 'X' then begin    ;Sun view?
  121.         s  = ['New Zoom Factor:',strtrim(indgen(19)+2,2)]
  122.         ifact = wmenu(s, init=ifact-1,title=0)+1
  123.         IF (!Version.Os NE 'MacOS') THEN $
  124.             tvcrs,x,y,/dev $    ;Restore cursor
  125.                 ELSE tvcrs,1
  126.         ierase = 1
  127.     endif else begin
  128.         Read,'Current factor is',ifact+0,'.  Enter new factor: ',ifact
  129.         if ifact le 0 then begin
  130.             ifact = 4
  131.             print,'Illegal Zoom factor.'
  132.             endif
  133.             ierase = 1    ;Clean out previous display
  134.     endelse
  135. else:    begin
  136.     x0 = 0 > (x-xs/(ifact*2))     ;left edge from center
  137.     y0 = 0 > (y-ys/(ifact*2))     ;bottom
  138.     nx = xs/ifact            ;Size of new image
  139.     ny = ys/ifact
  140.     nx = nx < (!d.x_vsize-x0)
  141.     ny = ny < (!d.y_size-y0)
  142.     x0 = x0 < (!d.x_vsize - nx)
  143.     y0 = y0 < (!d.y_vsize - ny)
  144.     a = tvrd(x0,y0,nx,ny)        ;Read image
  145.     if zoom_w lt 0 then begin    ;Make new window?
  146.         window,/free,xsize=xs,ysize=ys,title='Zoomed Image'
  147.         zoom_w = !d.window
  148.     endif else begin
  149.         wset,zoom_w
  150.         if ierase then erase        ;Erase it?
  151.         ierase = 0
  152.     endelse
  153.     xss = nx * ifact    ;Make integer rebin factors
  154.     yss = ny * ifact
  155.     tv,rebin(a,xss,yss,sample=1-keyword_set(interp))
  156.     wset,old_w
  157.     endcase
  158. endcase
  159. goto,again
  160.  
  161. done:
  162. IF NOT KEYWORD_SET(KEEP) THEN BEGIN
  163.         if zoom_w ge 0 then wdelete,zoom_w              ;Done with window
  164.         ZOOM_W = -1
  165. ENDIF
  166. zoom_win = zoom_w    ;Return index of zoom window to user
  167. end
  168.  
  169.